package user_assets_pix

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/assets-api/pkg/xerrors"
	"gitee.com/liuxuezhan/ar-platform/base-common/headInfo"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/jinzhu/copier"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPixWalletListPageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 分页查询
func NewUserPixWalletListPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPixWalletListPageLogic {
	return &UserPixWalletListPageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserPixWalletListPageLogic) UserPixWalletListPage(req *types.UserPixWalletsPageRequest) (resp *types.UserPixWalletsPageResponse, err error) {
	request := rpc.UserPixWalletsPageRequest{}
	err = copier.Copy(&request, req)
	if err != nil {
		return nil, xerrors.ErrDataConvert
	}
	request.Param.UserId = headInfo.GetTokenUid(l.ctx)
	page, err := l.svcCtx.AssetsRpc.UserChannel.UserPixWalletsPage(l.ctx, &request)
	response := types.UserPixWalletsPageResponse{}
	if err != nil {
		return &response, err
	}
	err = copier.Copy(&response, page)
	if err != nil {
		return nil, xerrors.ErrDataConvert
	}
	return &response, nil
}
